package Exception;

/**
 * @author 王艺锡
 * @version 1.0
 */
public class Exception01 {
    public static void main(String[] args) {
        //1.如果try代码块可能有多个异常
        //2.可以使用多个catch分别捕捉不同的异常，相应处理
        //3.要求子类要写在前面(NullPointerException,ArithmeticException)，父类异常写在后面(Exception)
        try {
            Person person = new Person();
            person = null;//NullPointerException
            int n1 = 10;
            int n2 = 0;
            int ret = n1 / n2;//ArithmeticException
        }catch (NullPointerException e){
            System.out.println("空指针异常捕获" + e.getMessage());
        }catch (ArithmeticException e){
            System.out.println("算数异常捕获" + e.getMessage());
        }catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }
}

class Person{
    private String name = "jack";

    public String getName() {
        return name;
    }

}
